//DHCOutPhPYSure

var tblobj=document.getElementById("tDHCOutPhPYSure");
var evtName;
var doneInit=0;
var focusat=null;
var SelectedRow = 0;
var pmiobj,pnameobj;
var stdateobj,enddateobj;
var phlobj,phwobj,locdescobj,phwdescobj,pydrobj,fydrobj,pynameobj,fynameobj;
var ctlocobj,useridobj;
var BResetobj,BPrintobj;
var printobj;
var GPhl
var ctloc=document.getElementById('ctloc').value
  

function BodyLoadHandler() {
  BResetobj=document.getElementById("BReset");
  if (BResetobj) BResetobj.onclick=Reset_click;
 var BPrescobj=document.getElementById("rPrescNo");
  if (BPrescobj) BPrescobj.onkeypress=Presc_KeyPress;
  
   var BPrescobj=document.getElementById("CUserCode");
  if (BPrescobj) BPrescobj.onkeypress=UserCode_KeyPress;

  
  var BSureobj=document.getElementById("BSure");
  if (BSureobj) BSureobj.onclick=Presc_Sure;

  ctlocobj=document.getElementById("ctloc");
  tblobj=document.getElementById("tDHCOutPhPYSure");
  if (tblobj.rows.length>1)
  {
	  DHCMZYF_setfocus("CUserCode");
	  }
  else
  {
	  DHCMZYF_setfocus("rPrescNo");
	  
  }
  var ctloc=document.getElementById('ctloc').value
var getmethod=document.getElementById('getphl');
     if (getmethod) {var encmeth=getmethod.value} else {var encmeth=''};
      GPhl=cspRunServerMethod(encmeth,ctloc)



}




function Reset_click()
{
	location.href="websys.default.csp?WEBSYS.TCOMPONENT=DHCOutPhPYSure";
 }
 
 
function UserCode_KeyPress()
{
	
	var rows=tblobj.rows.length
	if (rows==1){alert(t['norow']); return;}
	var ctloc=document.getElementById('ctloc').value
	var usercode=document.getElementById('CUserCode').value;
	
	 var key=websys_getKey(e);
	 if (key==13)
	 {
	  if (usercode=='') {alert(t['usercodeisnull']); return ;}	 
		 
	 var getmethod=document.getElementById('getpydr');
     if (getmethod) {var encmeth=getmethod.value} else {var encmeth=''};
     var retval=cspRunServerMethod(encmeth,usercode,ctloc)
     if (retval==0){
	     alert(t['notpydr']);return;
	    
	     }
	  else
	  {
		 
 document.getElementById('pydr').value =retval
 Presc_Sure()
  //  DHCMZYF_setfocus("BSure");
	  }   
	     
     
 
		 
	 }
}


function Presc_KeyPress()
{
	var prescno=document.getElementById('rPrescNo').value;
	var ctloc=document.getElementById('ctloc').value
	 var key=websys_getKey(e);
	 if (key==13)
	 {
	  if (prescno=='') {alert(t['isnull']);document.getElementById('rPrescNo').value=""; return ;}	 
		 
	 var getmethod=document.getElementById('getphdrow');
     if (getmethod) {var encmeth=getmethod.value} else {var encmeth=''};

     var retval=cspRunServerMethod(encmeth,prescno,ctloc)
     if (retval==0){
	     alert(t['nopresc']);
	     document.getElementById('rPrescNo').value=""
	     return;
	    
	     }
	  else
	  {
	 var  phdrow=retval
	 document.getElementById('rPhd').value=phdrow;
	// alert(retval)
	  location.href="websys.default.csp?WEBSYS.TCOMPONENT=DHCOutPhPYSure&rPhd="+phdrow+"&rCtloc="+ctloc;    
	  }
	
}
}


function Presc_Sure()
{
	
 var phdrow=document.getElementById('rPhd').value
 var pydr=document.getElementById('pydr').value 
 var ctloc=document.getElementById('ctloc').value 
 if (pydr=='') {alert(t['notpydr']);return ;}	

var getmethod=document.getElementById('sure');
     if (getmethod) {var encmeth=getmethod.value} else {var encmeth=''};
  var retval=cspRunServerMethod(encmeth,phdrow,ctloc,pydr)

 //var retval=0
     if (retval=='0')
     {
	     
	  
	     
	 var getmethod=document.getElementById('getscpath');
   if (getmethod) {var encmeth=getmethod.value} else {var encmeth=''};
   var scpath=cspRunServerMethod(encmeth,GPhl)
   
  
   if (scpath!="-1")
   {
   	var getmethod=document.getElementById('SendDHCall');
   if (getmethod) {var encmeth=getmethod.value} else {var encmeth=''};
   var retcall=cspRunServerMethod(encmeth,phdrow,"")
  //if (retcall!="0") {alert(t['ScreenError'])}
  }
   
   /* 
   {
	    var getmethod=document.getElementById('getphw');
       if (getmethod) {var encmeth=getmethod.value} else {var encmeth=''};
        var retwin=cspRunServerMethod(encmeth,phdrow,ctloc)
       var windr=retwin.split("^")[0]       
       var windesc=retwin.split("^")[1]
       
	   var getmethod=document.getElementById('getwfpat');
       if (getmethod) {var encmeth=getmethod.value} else {var encmeth=''};

       var wfpat=cspRunServerMethod(encmeth,GPhl,windr)
       //alert(wfpat)
       if (wfpat!="-1")
       {
         
         var sstr=wfpat.split("^")
         var wfrow=sstr.length
         var pattail=""
         var lt=0
           var spacestr=" "
         for (i=0;i<wfrow;i++)
          {
	        var patstr=sstr[i]
	        if ((i+1)%2==0)
	        {
		      patstr=patstr+"\r\n"
	        }
	         
	        else
	        {
		       var patnamelen=sstr[i].length
		        var allspace=""
		        var zzlen=sstr[i].replace(/[^\xoo-\xff]/g,"aa").length
		        //alert(zzlen)
		        if (zzlen<9)
		        {
			        for (lt=1;lt<=9-zzlen;lt++)
			        {
				      allspace=allspace+spacestr  
			        }
			        
		        }
		        
		       //alert(patstr+allspace+"$$")
		        patstr=patstr+allspace
		         
	        }
	       //alert(pattail+patstr+"##")
	       pattail=pattail+patstr 
	   
          }
         var getmethod=document.getElementById('getfilename');
        if (getmethod) {var encmeth=getmethod.value} else {var encmeth=''};
        var filename=cspRunServerMethod(encmeth,windesc)
        //alert(filename)
        if (filename==-1) return;
       //alert(pattail)
        var fso = new ActiveXObject("WScript.NetWork");
        var fs = new ActiveXObject("Scripting.FileSystemObject");
        var FileStr=scpath+'\\'+filename+'.txt';
        //alert(FileStr)
        var fw=fs.CreateTextFile(FileStr,true);
    	  fw.WriteLine(pattail);
    	  fw.Close();
       	  
        
       }
	
   
   }
  */   
	     
	     //alert(t['qrok']);
     	Reset_click();
	     
     }
    else
    {
	    alert(t['qrerr']);
	    document.getElementById("CUserCode").value="";
	   DHCMZYF_setfocus("CUserCode"); 
    }
	
	
	
}
 
function DHCMZYF_setfocus(objName) {
	window.setTimeout('DHCMZYF_setfocus2(\''+objName+'\')',300);
}

function DHCMZYF_setfocus2(objName) {
	var obj=document.getElementById(objName);
	if (obj) {
		try {obj.focus();obj.select();	} catch(e) {}  }
    }

document.body.onload = BodyLoadHandler;
